<?php
/**
*	onlyoffice回调
*/ 
class onlyofficeClassAction extends apiAction
{

	/**
	*	编辑回调
	*/
	public function editcallAction()
	{
		$result 	= $this->getpostdata();
		$data   	= json_decode($result, true);
		$status 	= arrvalue($data,'status');
		
		$filenum 	= $this->get('filenum');
		$frs		= m('file')->getone("`filenum`='$filenum'");
		if(!$frs)return '{"error":0}';
		
		$optid 		= (int)$this->get('optid','0');
		$optname 	= $this->jm->base64decode($this->get('optname'));
		
		$newext = $frs['fileext'];
		if($newext=='xls')$newext = 'xlsx';
		if($newext=='doc')$newext = 'docx';
		if($newext=='ppt')$newext = 'pptx';
		
		//打开编辑时
		if($status=='1'){
		}
		
		//编辑完成
		if($status=='2'){
			$nurl 	  = $data['url'];
			$filepath = ''.UPDIR.'/'.date('Y-m').'/only_'.date('dHis').'_'.rand(1000,9999).'.'.$newext.'';
			$cont 	  = @file_get_contents($nurl);
			if(!$cont)return '{"error":1,"msg":"没用文件"}';
			$bo = $this->rock->createtxt($filepath, $cont);
			if(!$cont)return '{"error":1,"msg":"保存失败"}';
			
			m('file')->editcall($filenum, $filepath, $newext);
		}
		//$this->rock->debugs($result,'onlycall');
		
		return '{"error":0}';
	}
	
	
	
}